const app = getApp();
let page = 10;
Page({
  data: {
    curIndex: 0,
    goods_eval_list: [],
    hasMore: true,
    curpage: 1,
    type: 0,
    jetbrains:false
  },
  onLoad: function (options) {
    let goods_id = options.goods_id;
    this.getEvalList(goods_id);
    let wh = app.globalData.wh;
    this.setData({
      scrollHeight: wh,
      goods_id: goods_id
    })
  },
  changeIndex: function (e) {
    let curIndex = e.currentTarget.dataset.index;
    let type = e.currentTarget.dataset.type;
    this.setData({
      curIndex: curIndex,
      goods_eval_list: [],
      hasMore: true,
      curpage: 1,
    })
    this.getEvalList(this.data.goods_id, type);
  },
  getEvalList: function (goods_id, type) {
    if (!type) {
      type = ''
    }
    let self = this;
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=goods&op=goods_evaluate',
      data: {
        goods_id: goods_id,
        type: type,
        curpage: self.data.curpage,
        page: page,
      },
      method: 'GET',
      success: res => {
        if (res.data.code == 200) {
          self.data.hasMore = res.data.hasmore;
          self.setData({
            goods_eval_list: self.data.goods_eval_list.concat(res.data.datas.goods_eval_list)
          })
          if (self.data.hasMore) {
            self.data.curpage++
          }
          if (res.data.datas.goods_eval_list.length == 0) {
            self.setData({
              noneEval: true
            })
          }
        } else {
          wx.showToast({
            title: res.data.error,
            icon: 'none'
          })
        }
      }
    })
  },
  getMoreEval: function () {
    if (this.data.hasMore) {
      this.getEvalList(this.data.goods_id)
    }
  },
})